<template>

  <!--
      作者 luoyiming
      时间：2020-08-30
      描述：设置-满额包邮
  -->
  <div class="product-add">
    <!--form表单-->
    <el-form size="small" ref="form" :model="form" label-width="200px">
      <div class="common-form">滿額包郵設定</div>

      <el-form-item label="是否開啟滿額包郵">
        <div>
          <el-radio v-model="form.isOpen" :label="1">開啟</el-radio>
          <el-radio v-model="form.isOpen" :label="0">關閉</el-radio>
        </div>
      </el-form-item>
      <el-form-item label="單筆訂單滿" prop="money" :rules="[{required: true,message: ' '}]">
        <el-input v-model="form.money" type="number" style="width: 200px;"></el-input>元<div class="tips">如果開啟滿額包郵，設置0為全場包郵</div>
      </el-form-item>
      <!--提交-->
      <div class="common-button-wrapper">
        <el-button type="primary" @click="onSubmit" :loading="loading">提交</el-button>
      </div>
    </el-form>
  </div>

</template>

<script>
import SettingApi from '@/api/setting.js';
export default {
  data() {
    return {
      form: {
        isOpen: '',
        money: ''
      },
      loading: false
    };
  },
  created() {
    this.getData();
  },
  methods: {
    getData() {
      let self = this;
      SettingApi.fullfreeDetail({}, true).then(res => {
        let vars = res.data;
        self.form.isOpen = vars.isOpen;
        self.form.money = vars.money;
      }).catch(error => {});
    },
    //提交表单
    onSubmit() {
      let self = this;
      let params = this.form;
      self.$refs.form.validate(valid => {
        if (valid) {
          self.loading = true;
          SettingApi.editFullfree(params, true).then(res => {
            self.loading = false;
            ElMessage({
              message: "恭喜您，設定成功",
              type: 'success'
            });
          }).catch(error => {
            self.loading = false;
          });
        }
      });
    }
  }
};
</script>

<style scoped>
.tips {
    color: #ccc;
  }
</style>

